﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Biblioteca.Interfaces;
using System.Data;

namespace Biblioteca.Models
{
    public class AutorModel : IAutor
    {
        private BibliotecaStore db;

        public AutorModel(BibliotecaStore data)
        {
            this.db = data;
        }

        public void crearAutor(Autor a)
        {
            db.Autors.AddObject(a);
            db.SaveChanges();
        }

        public void eliminarAutor(Autor autor)
        {
            db.Autors.DeleteObject(autor);
            db.SaveChanges();
        }

        public void modificarAutor(Autor am)
        {
            db.Autors.Attach(am);
            db.ObjectStateManager.ChangeObjectState(am, EntityState.Modified);
            db.SaveChanges();
        }

        public Autor getSingle(int idAutor)
        {
            return db.Autors.Single(a => a.IdAutor == idAutor);
        }

        public IList<Autor> getAll()
        {
            return db.Autors.OrderBy(m => m.Apellido).ToList();
        }
    }
}